package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author Pan Rundong
 * @Date 2023-02-27 19:59
 * @Desc 交友Controller
 */
@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 今日佳人功能
     *
     * @param
     * @return org.springframework.web.bind.annotation.ResponseBody
     * @Author Pan Rundong
     */
    @GetMapping("/todayBest")
    public ResponseEntity<TodayBest> todayBest() {
        //1.调用service
        TodayBest todayBest = tanhuaService.todayBest();
        //2.返回
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 首页推荐
     *
     * @param recommendUserDto
     * @return org.springframework.http.ResponseEntity<com.tanhua.model.dto.RecommendUserDto>
     * @Author Pan Rundong
     */
    @GetMapping("/recommendation")
    public ResponseEntity<PageResult> recommendation(RecommendUserDto recommendUserDto) {
        //1.调用service
        PageResult page = tanhuaService.recommendation2(recommendUserDto);
        //2.返回
        return ResponseEntity.ok(page);
    }

    /**
     * 根据Id查询佳人信息
     *
     * @param
     * @return org.springframework.http.ResponseEntity<com.tanhua.model.vo.TodayBest>
     * @Author Pan Rundong
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity<TodayBest> personalInfo(@PathVariable Long id) {
        TodayBest todayBest = tanhuaService.getById(id);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查看佳人问题
     *
     * @param userId
     * @return org.springframework.http.ResponseEntity<java.lang.String>
     * @Author Pan Rundong
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity<String> strangerQuestions(Long userId) {
        String questions = tanhuaService.getQuestion(userId);
        return ResponseEntity.ok(questions);
    }

    /**
     * 回复陌生人信息
     *
     * @param map
     * @return org.springframework.http.ResponseEntity
     * @Author Pan Rundong
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity reply(@RequestBody Map map) {
        //获取map信息
        Long userId = Long.valueOf(map.get("userId").toString());
        String reply = map.get("reply").toString();
        tanhuaService.reply(userId, reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花推荐查询列表
     *
     * @param
     * @return org.springframework.http.ResponseEntity<java.util.List>
     * @Author Pan Rundong
     */
    @GetMapping("cards")
    public ResponseEntity<List> cards() {
        List<TodayBest> list = tanhuaService.cards();
        return ResponseEntity.ok(list);
    }

    /**
     * 左滑喜欢
     *
     * @param id
     * @return org.springframework.http.ResponseEntity
     * @Author Pan Rundong
     */
    @GetMapping("{id}/love")
    public ResponseEntity love(@PathVariable Long id) {
        tanhuaService.love(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 右滑不喜欢
     *
     * @param id
     * @return org.springframework.http.ResponseEntity
     * @Author Pan Rundong
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity unLove(@PathVariable Long id) {
        tanhuaService.unLove(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近的人
     *
     * @param gender
     * @param distance
     * @return org.springframework.http.ResponseEntity<java.util.List>
     * @Author Pan Rundong
     */
    @GetMapping("search")
    public ResponseEntity<List> search(String gender, Double distance) {
        List<NearUserVo> list = tanhuaService.search(gender, distance);
        return ResponseEntity.ok(list);
    }
}
